<?php

class News_content_model extends CI_Model
{
    private $table = 'news_content';
    private $table_2 = 'news_class';

    public function page_list($page_num, $num, $param)
    {
        $this->db->select('news.id,
                         news.title,
                         news.content,
                         news.class_id,
                         news.pv,
                         news.status,
                         news.author,
                         news.create_time,
                         news.edit_time,
                         news.image,
                         newsclass.class_name,
                         newsclass.status,
                         newsclass.sort');
        $this->db->from($this->table . ' as news');
        $this->db->join($this->table_2 . ' as newsclass', 'news.class_id = newsclass.class_id');
        $this->db->where('newsclass.status', '1');//类目上架
        $this->db->where('news.status', '1');//资讯上架
        if ( !empty($param['class_id']) ) {
            $this->db->where('news.class_id', $param['class_id']);
        }
        $this->db->order_by('news.edit_time DESC, news.pv ASC');
        $this->db->limit($page_num, $num);

        return $this->db->get();
    }

    public function findById($id)
    {
        $this->db->select('news.id,
                         news.title,
                         news.content,
                         news.class_id,
                         news.pv,
                         news.status,
                         news.author,
                         news.create_time,
                         news.edit_time,
                         news.image,
                         newsclass.class_name,
                         newsclass.status,
                         newsclass.sort');
        $this->db->where('news.id', $id);
        $this->db->from($this->table . ' as news');
        $this->db->join($this->table_2 . ' as newsclass', 'news.class_id = newsclass.class_id');
        $this->db->where('newsclass.status', '1');//类目上架
        $this->db->where('news.status', '1');//资讯上架

        return $this->db->get();
    }

    public function informationTutor($page_num, $num, $param)
    {
        $this->db->select('news.id,
                         news.title,
                         news.content,
                         news.class_id,
                         news.pv,
                         news.status,
                         news.author,
                         news.create_time,
                         news.edit_time,
                         news.image,
                         newsclass.class_name,
                         newsclass.status,
                         newsclass.sort');
        $this->db->from($this->table . ' as news');
        $this->db->join($this->table_2 . ' as newsclass', 'news.class_id = newsclass.class_id');
        $this->db->where('newsclass.status', '1');//类目上架
        $this->db->where('news.status', '1');//资讯上架
        if ( !empty($param['class_id']) ) {
            $this->db->where('news.class_id', $param['class_id']);
        }
        if ( !empty($param['id']) ) {
            $this->db->where('news.id <', $param['id']);
        }
        $this->db->order_by('news.id DESC');
        $this->db->limit($page_num, $num);

        return $this->db->get();
    }

}